package com.jml.service;

import com.jml.entity.User;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

// 设置动态用户信息
@Service
public class MyUserDetailsService implements UserDetailsService {

	@Autowired
	private PasswordEncoder passwordEncoder;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

		// 1.根据用户名称查询数据用户信息
		//User user = userMapper.findByUsername(username);
		User user =new User();
		user.setUsername(username);
		//模拟数据库中查的数据密码
		String password = passwordEncoder.encode("123456");
		user.setPassword(password);
		user.setId(123321);
				//这四个字段默认是true，可以不写，也可以根据表中的字段填写
		//账户可用(逻辑删除)
		user.setEnabled(true);
		// 账户过期
		user.setAccountNonExpired(true);
		//密码过期
		user.setCredentialsNonExpired(true);
		//账户锁定(冻结)
		user.setAccountNonLocked(true);
		return user;

	}

}
